//
// Created by xy on 2024/10/22.
//

#ifndef WEBDESK_UTILS_SAFEQUEUE_H_
#define WEBDESK_UTILS_SAFEQUEUE_H_

#include <bits/pthreadtypes.h>
#include <stdbool.h>

typedef struct {
  void** buffer;     // 存储队列数据的缓冲区
  int capacity;      // 队列的容量
  int front;         // 队列头部索引
  int rear;          // 队列尾部索引
  int size;          // 当前队列大小
  pthread_mutex_t mutex; // 互斥锁
} ThreadSafeCircularQueue;

void queue_init(ThreadSafeCircularQueue* queue, int capacity);
void queue_destroy(ThreadSafeCircularQueue* queue);
bool queue_push(ThreadSafeCircularQueue* queue, void* data);
void* queue_pop(ThreadSafeCircularQueue* queue);
bool queue_is_empty(ThreadSafeCircularQueue* queue);
bool queue_is_full(ThreadSafeCircularQueue* queue);
int size(ThreadSafeCircularQueue* queue);


#endif //WEBDESK_UTILS_SAFEQUEUE_H_
